package ar.edu.unq.wannaplay.main;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import org.apache.wicket.Page;
import org.apache.wicket.Request;
import org.apache.wicket.Response;
import org.apache.wicket.Session;
import org.apache.wicket.authentication.AuthenticatedWebApplication;
import org.apache.wicket.authentication.AuthenticatedWebSession;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;

import ar.edu.unq.wannaplay.pages.LoginPage;

public class WPApplication extends AuthenticatedWebApplication {

    public static final List<Locale> LOCALES = Arrays.asList(new Locale[] { Locale.ENGLISH, new Locale("es") });

    @Override
    public void init() {
        // getResourceSettings().;

        MounterURL aMounterURL = new MounterURL(this);
        this.addComponentInstantiationListener(new SpringComponentInjector(this));
        // aMounterURL.mount("home", Home.class, "");
        aMounterURL.mount("loginPage", LoginPage.class, "");
    }

    @Override
    public Class<? extends Page> getHomePage() {
        return LoginPage.class;
    }

    @Override
    protected Class<? extends AuthenticatedWebSession> getWebSessionClass() {
        return WebSession.class;
    }

    @Override
    protected Class<? extends WebPage> getSignInPageClass() {
        return LoginPage.class;
    }

    @Override
    public Session newSession(final Request request, final Response response) {
        WebSession session = new WebSession(request);
        Locale locale = session.getLocale();
        if (!LOCALES.contains(locale)) {
            session.setLocale(Locale.ENGLISH);
        }
        return session;
    }
}
